package com.rayboo.repository;

import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.rayboo.model.ClubUser;

/**
 * 
 * ClubUserRepository
 * 
 * @author ray
 * @date 2016年9月8日 下午8:11:37
 *
 */
public interface ClubUserRepository extends CrudRepository<ClubUser, Integer> {
	/**
	 * 分页查询用户列表
	 * 
	 * @param pageable
	 * @return
	 */
	@Query("SELECT u from ClubUser u order by u.createtime desc")
	List<ClubUser> findAll(Pageable pageable);

	/**
	 * 根据条件分页查询
	 * 
	 * @param query
	 * @param pageable
	 * @return
	 */
	@Query("SELECT u from ClubUser u where u.phone like %:query% or u.name like %:query% or u.userString like %:query% order by u.createtime desc")
	List<ClubUser> find(@Param("query") String query, Pageable pageable);

	/**
	 * 根据条件查询数量
	 * 
	 * @param query
	 * @return
	 */
	@Query("SELECT count(u) from ClubUser u where u.phone like %:query% or u.name like %:query% or u.userString like %:query% ")
	int count(@Param("query") String query);

	/**
	 * 根据userid查询用户信息
	 * 
	 * @param userId
	 * @return
	 */
	@Query("SELECT u from ClubUser u where userid = :userid")
	ClubUser findByUserId(@Param("userid") long userId);
}
